import sys,os,cgi,time
sys.path.insert(0, os.path.split(sys.path[0])[0])

import cnd
import job
import tag

query = os.getenv("QUERY_STRING",'') 
kwargs = cgi.parse_qs(query)
date = kwargs.get('date',[time.strftime("%Y%m%d")])[0]
job_name = kwargs.get('job',[''])[0].lower()
kind = kwargs.get('kind',[''])[0].lower()
remove = kwargs.get('remove',['0'])[0].lower()

if False:
	print "HTTP/1.1 200 ok"
	print "Content-Type: text/html"     # HTML is following
	print
else:
	import head
	head.header(banner=False,action='force',tags=tag.job_tags(job_name))

if remove in ('1','yes','on','true'):
	cnd.clear(job_name+'.'+kind,date)
else:
	cnd.add(job_name+'.'+kind,date)

print """<html><head>
<meta HTTP-EQUIV="REFRESH" content="0; url=job.py?date=%s&job=%s">
</head><body></body></html>""" % (date,job_name)
